package com.weishenai.customerassistant.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.weishenai.customerassistant.entity.sys.SysRoleEntity;
import com.weishenai.customerassistant.mapper.SysRoleMapper;
import com.weishenai.customerassistant.service.SysRoleService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author weishenai
 * @since 2021-11-27
 */
@Service
public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRoleEntity> implements SysRoleService {

    @Override
    public List<SysRoleEntity> ListRolesByUserId(Long id) {
        List<SysRoleEntity> sysRoles = this.list(new QueryWrapper<SysRoleEntity>()
                .inSql("id", "select role_id from sys_user_role where user_id =" + id));

        return sysRoles;
    }

    @Override
    public Page<SysRoleEntity> getRoleList(String name,long currentPage, long pageSize ) {
        return this.page(new Page<>(currentPage,pageSize ),
                Wrappers.lambdaQuery(SysRoleEntity.class)
                        .like(StrUtil.isNotBlank(name), SysRoleEntity::getName, name));

    }
}
